package com.cyanite.playlv2api.parsers.json;

import com.cyanite.playlv2api.types.Message;

import org.json.JSONException;
import org.json.JSONObject;

public class MessageParser extends AbstractParser<Message> {

    @Override
    public Message parse(JSONObject json) throws JSONException {
        Message obj = new Message();
        if (json.has("mid")) {
            obj.setId(String.valueOf(json.getInt("mid")));
        }
        if (json.has("nick")) {
            obj.setUserName(json.getString("nick"));
        }
        if (json.has("new")) {
            obj.setIsReaded(json.getInt("new")==1?false:true);
        }
        if (json.has("date")) {
            obj.setDate(json.getString("date"));
        }
        if (json.has("name")) {
            obj.setTitle(json.getString("name"));
        }
        if (json.has("uid")) {
            obj.setUserId(String.valueOf(json.getInt("uid")));
        }
        if (json.has("tid")) {
            obj.setTripId(String.valueOf(json.getString("tid")));
        }
        if (json.has("tname")) {
            obj.setTripName(json.getString("tname"));
        }
        return obj;
    }
}